<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('月度数据导入数据原始表列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">供电所名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="supplyName" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">任务年月</label>
                <div class="layui-input-inline">
                    <input type="text" name="taskmonth" placeholder="" class="layui-input" id="taskmonth">
                </div>
                <label class="layui-form-label">分公司</label>
                <div class="layui-input-inline">
                    <select name="subcompanyId" lay-filter="aihao">
                        <option value=""></option>
                        <option value="1">国网阜新蒙古族自治县供电公司</option>
                        <option value="2">国网阜新市清河门区供电公司</option>
                        <option value="3">国网阜新市细河区供电公司</option>
                        <option value="4">国网彰武县供电公司</option>
                        <option value="5">国网阜新市市南供电公司</option>

                    </select>
                </div>
                <label class="layui-form-label">任务类型描述</label>
                <div class="layui-input-inline">
                    <input type="text" name="typeMemo" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">对应指标id</label>
                <div class="layui-input-inline">
                    <input type="text" name="targetId" placeholder="" class="layui-input">
                </div>

            </div>
            <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                    lay-filter="autoOriimport-query">
                <i class="layui-icon layui-icon-search"></i>
                查询
            </button>
            <button type="reset" class="pear-btn pear-btn-md">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="autoOriimport-table" lay-filter="autoOriimport-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="autoOriimport-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md"
            id="uploadFile">
        <i class="layui-icon layui-icon-add-1"></i>
        导入
    </button>

</script>


<script type="text/html" id="autoOriimport-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery', 'upload'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var MODULE_PATH = rootPath + "/AutoOriimportController/";
        var cols = [
            [
                {title: '供电所编号', field: 'supplyId', align: 'center'},

                {title: '供电所名称', field: 'supplyName', align: 'center'},

                {title: '分公司编号', field: 'subcompanyId', align: 'center'},

                {title: '分公司名称', field: 'subcompanyName', align: 'center'},

                {title: '任务年月', field: 'taskmonth', align: 'center'},

                {title: '任务类型描述', field: 'typeMemo', align: 'center'},

                {title: '对应系统指标id', field: 'targetId', align: 'center'},

                {title: '数值', field: 'value', align: 'center'},

                {title: '单位', field: 'unit', align: 'center'}

            ]
        ]

        var year = new Date().getFullYear()
        var month = new Date().getMonth();
        month = (month < 10 ? "0" + month : month);
        if (month == '00') {
            month = 12
            year = year - 1
        }
        laydate.render({
            elem: '#taskmonth' //指定元素
            , type: 'month'
            , value: year + "-" + month
        })

        //table表单列表
        table.render({
            elem: '#autoOriimport-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#autoOriimport-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }],
            where: {'taskmonth': year + "-" + month},
            done: function (res) {
                uploadT();
            }
        });

        //table图标事件绑定
        table.on('tool(autoOriimport-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(autoOriimport-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(autoOriimport-query)', function (data) {
            table.reload('autoOriimport-table', {where: data.field})
            return false;
        });

        function uploadT() {
            upload.render({
                elem: '#uploadFile',
                url: MODULE_PATH + 'uploadAutoOriimport',
                exts: 'xls',
                done: function (res) {

                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 1000});
                        table.reload('autoOriimport-table')

                    } else {
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                },
                error: function (err) {
                    debugger
                    layer.alert('导入出现异常', {icon: 2});
                }
            });
        }


        //刷新按钮
        window.refresh = function () {
            table.reload('autoOriimport-table');

        }


    })
</script>
</html>